<template>
  <div class="store-permission padding-top">
    <div class="agentList" style="width:100%;">
      <el-table
        :data="aList"
        border
        style="width: 100%"
        ref="table"
        :height="oHeight"
        :header-cell-style="{'text-align':'center'}"
        :cell-style="{'text-align':'center'}"
      >
        <!-- <el-table-column type="index" width="50" label="序号"></el-table-column> -->
        <el-table-column fixed prop="depart_id" label="序号" key="store_id"></el-table-column>
        <el-table-column
          prop="depart_name"
          label="组合名称"
          key="depart_name"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="store_count"
          label="经销商数量"
          key="store_owner"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="admin_count"
          label="管理员人数"
          key="member_id"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          fixed="right"
          align="center"
          label="操作"
          key="operate"
          width="160"
          v-if="admin_type == 2"
        >
          <template slot-scope="scope">
            <el-button class="operateBtn" type="text" @click="edit(scope.row)">编辑</el-button>
            <el-button class="operateBtn" type="text" @click="deleter(scope.row.depart_id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- <pagination
        :arr="aList"
        :total="total"
        :currentPage="currentPage"
        :handleSizeChange="handleSizeChange"
        :handleCurrentChange="handleCurrentChange"
      ></pagination>-->
    </div>
  </div>
</template>

<script>
import pagination from "@/components/pagination/pagination.vue";
import { resize } from "@/common/js/height.js";
export default {
  data() {
    return {
      searchObj: {
        //该变量定义查询传参
        depart_id: this.$store.state.user_info.first_depart_id,
      },
      aList: [],
      oHeight: 800,
      total: 1,
      currentPage: 1,
      admin_type: this.$store.state.user_info.admin_type
    };
  },
  components: {
    pagination
  },
  created() {},
  props: ["changed"], //父子组件传值---小组
  methods: {
    // 获取列表
    getList() {
      var that = this;
      this.$http
        .post(
          "/admin/depart/index.php?act=departManage&op=groupList",
          this.searchObj
        )
        .then(
          res => {console.log(res)
            if (res.code == 1) {
              if (res.data[0]) {
                this.aList = res.data;
                // this.total = parseInt(res.data[0].child.length);
              }
            } else {
              this.$message.error("获取数据失败！");
              // alert(res.msg);
              this.aList = [];
            }
          },
          err => {
            this.$message.error("获取数据失败！");
          }
        );
    },
    // 删除店铺
    deleter(id) {
      this.$confirm("确认删除？")
        .then(_ => {
          this.$http
            .post("/admin/depart/index.php?act=departManage&op=delGroup", {
              depart_id: id
            })
            .then(
              res => {
                if (res.code == 1) {
                  this.$message({
                    showClose: true,
                    message: res.msg,
                    type: "success"
                  });
                  this.getList();
                } else {
                  this.$message({
                    showClose: true,
                    message: res.msg,
                    type: "error"
                  });
                }
              },
              err => {
                this.$message({
                  showClose: true,
                  message: res.msg,
                  type: "error"
                });
              }
            );
          done();
        })
        .catch(_ => {});
    },
    // 点击编辑
    edit(row) {
      this.$store.commit("SET_VALUE", {
        name: row.depart_name,
        id: row.depart_id,
        parent: row.parent_id
      });
      this.$router.push({
        path: "couple",
        query: {
          id: row.depart_id
        }
      });
    },
    // 改变当前页
    handleCurrentChange: function(val) {
      this.searchObj.page = val;
      this.currentPage = val;
      /*请求数据*/
      this.getList();
    },
    //分组一页多少数据
    handleSizeChange(val) {
      this.currentPage = 1;
      this.searchObj.page = 1;
      this.searchObj.pageSize = val;
      /*请求数据*/
      this.getList();
    }
  },
  watch: {
    changed(n, o) {
      this.getList();
    }
  },
  mounted() {
    //页面刷新就执行
    localStorage.eachNum = "";
    this.getList();
    resize(this);
    this.$nextTick(() => {
      this.$refs.table.doLayout(); //解决表格错位
    });
  }
};
</script>

<style scoped lang="scss">
</style>
